package com;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 * Dialog nos permite manejar un JDialog en base a un diseño establecido 
 * 
 * @author Alex Munoz and Mauricio Orellana
 * @version 2012-07-13
 */
public class Dialog extends JDialog implements ActionListener
{

    private JButton cerrar;
    
    /**
     * Constructor de objetos de la clase Dialog
     * @param title titulo del JDialog
     */
    public Dialog(String title)
    {
        super();
        this.setTitle(title);
        this.cerrar = new JButton(CommandNames.CLOSE);
        this.cerrar.addActionListener(this);
        this.setLayout(new GridBagLayout());
        this.setIconImage(Icons.LOGO.getImg());
        this.setModal(true);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    /**
     * Añadir contenido
     * 
     * @param Jpanel que desea ser mostrado en el JDialog
     */
    public void setcontenido(JPanel panel)
    {
        this.add (panel, this.gererarGBC(0, 0, 3, 1));
        this.add (cerrar, this.gererarGBC(2, 1, 1, 1));    
        this.pack();
    }
    
    /**
     * generarGBC permite simplificar el uso de gridBagLayout
     * 
     * @param gridx posicion x en el grid
     * @param gridy posicion y en el grid
     * @param gridWidth cuantas usara de ancho
     * @param gridheight cuantas usara de alto
     * @return GridBagConstraints con los parametros
     */
    public GridBagConstraints gererarGBC(int gridx, int gridy, int gridWidth, int gridheight)
    {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = gridx;
        gbc.gridy = gridy;
        gbc.gridwidth = gridWidth;
        gbc.gridheight = gridheight;
        return gbc;
    }
    
    /**
     * 
     */
    @Override
    public void actionPerformed(ActionEvent e)
    {
        this.dispose();
    }
}    

